#define __STDC_WANT_LIB_EXIT__ 1
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

typedef struct Horse Horse;

struct Horse{
  int age;
  int height;
  char name[20];
  char father[20];
  char monther[20];
  Horse* next;
  Horse* previous;
};

int main(void){
  Horse* first = NULL;
  Horse* current = NULL;
  Horse* last = NULL;
  
  char test='\0';
  
  for(;;){
    printf("Do you want to enter details of a%s horse (Y/N)?",first != NULL?"nother":"");
    scanf(" %c",&test);
    
    if(tolower(test) == 'n'){
      break;
    }
    current = (Horse*) malloc(sizeof(Horse));
    if(first == NULL){
      first = current;
      current->previous = NULL;
    }else{
      last->next = current;
      current->previous = last;
    }
    printf("名字：\n");
    scanf("%s",current->name);
    
    printf("年龄：\n");
    scanf("%d",&current->age);
    
    printf("身高/厘米：\n");
    scanf("%d",&current->height);
    
    printf("父亲：\n");
    scanf("%s",current->father);
    
    printf("母亲：\n");
    scanf("%s",current->monther);
    
    current->next = NULL;
    last = current;
    
  }
  printf("\n");
  while(current != NULL){
    printf("%s%d岁了，有%d厘米高，爸爸是%s，妈妈是%s。\n",current->name,current->age,current->height,current->father,current->monther);
    last = current;
    current = last->previous;
    free(last);
    last = NULL;
  }
  first = NULL;
  return 0;
}
